package com.wanxi.spring.cloud.user.controller;


import com.wanxi.spring.cloud.commons.api.CommonResult;
import com.wanxi.spring.cloud.user.model.User;
import com.wanxi.spring.cloud.user.model.UserRole;
import com.wanxi.spring.cloud.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 蒋帆
 * @since 2020-12-21
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/getUserByName")
    public CommonResult getUserByName(@RequestParam String username) {
        return userService.getUserByName(username);
    }

    @PostMapping("/register")
    public CommonResult register(@RequestBody User user) {
        return userService.register(user);
    }

    @GetMapping("/getUsers")
    public CommonResult getUsers(@RequestParam Map map) {
        return userService.getUsers(map);
    }

    @GetMapping("/deleteUser")
    public CommonResult deleteUser(@RequestParam String code){
        return userService.deleteUser(code);
    }

    @PostMapping("/updateUser")
    public CommonResult updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    @GetMapping("/getCodeList")
    public CommonResult getCodeList(){
        return userService.getCodeList();
    }

    @PostMapping("/updateStatus")
    public CommonResult updateStatus(@RequestParam("code") String code, @RequestParam("status") String status){
        return userService.updateStatus(code,status);
    }

    @GetMapping("/getLeaderList")
    public CommonResult getLeaderList(){
        return userService.getLeaderList();
    }

    @GetMapping("/getCoachList")
    public CommonResult getCoachList(){
        return userService.getCoachList();
    }

    /**
     * 小组成员管理
     * @param teamId
     * @return
     */
    @GetMapping("/getTeamUser")
    public CommonResult getTeamUser(@RequestParam Integer teamId){
        return userService.getTeamUser(teamId);
    }

    @GetMapping("/getTeamMember")
    public CommonResult getTeamMember(@RequestParam Integer teamId){
        return userService.getTeamMember(teamId);
    }

    /**
     * 签到管理
     * @param userId
     * @return
     */
    @GetMapping("/getTeamMemberByUser")
    public CommonResult getTeamMemberByUser(@RequestParam Integer userId){
        return userService.getTeamMemberByUser(userId);
    }
    @GetMapping("/getNoSignTeamMemberByUser")
    public CommonResult getNoSignTeamMemberByUser(@RequestParam Integer userId){
        return userService.getNoSignTeamMemberByUser(userId);
    }

    /**
     * openfeign
     * @param id
     * @return
     */

    @GetMapping("/selectUserById")
    public User selectUserById(@RequestParam int id){
        return userService.selectUserById(id);
    }

    @GetMapping("/getUserByCode")
    public User getUserByCode(@RequestParam String code){
        return userService.getUserByCode(code);
    }

    @GetMapping("/updateUserRole")
    public int updateUserRole(@RequestBody UserRole userRole){
        return userService.updateUserRole(userRole);
    }

}
